<!-- 工作总结管理 -->
<template>
    <div>
        <div class="search">
            <el-form :inline="true" :model="searchData" size="mini" class="demo-form-inline">
                <el-form-item label="" prop="peopleType">
                    <el-select v-model="searchData.peopleType">
                        <el-option label="总结人" value="1"></el-option>
                        <el-option label="点评人" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="" prop="ws_did">
                    <el-select v-model="searchData.ws_did" @change="obtainUser">
                        <el-option label="全部" value="0"></el-option>
                        <!-- <el-option v-for="(item,index) in optionName" :key="index" :label="item.name" :value="item.id"></el-option> -->
                        <el-option-group v-for="group in optionName" :key="group.label" :label="group.label">
                            <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-option-group>
                    </el-select>
                </el-form-item>
                <el-form-item label="" prop="ws_uid">
                    <el-select v-model="searchData.ws_uid">
                        <el-option label="全部" value="0"></el-option>
                        <el-option v-for="(item,index) in userType" :key="index" :label="item.u_username" :value="item.u_id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="" prop="dateType">
                    <el-select v-model="searchData.dateType">
                        <el-option label="总结日" value="1"></el-option>
                        <el-option label="点评日" value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="" prop="start_time">
                    <el-date-picker type="date" placeholder="请选择" v-model="searchData.start_time" value-format="yyyy-MM-dd"></el-date-picker>
                </el-form-item>
                <el-form-item label="" prop="end_time">
                    <el-date-picker type="date" placeholder="请选择" v-model="searchData.end_time" value-format="yyyy-MM-dd"></el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search" size="mini">查询</el-button>
                    <el-button type="primary" @click="add" size="mini">添加工作总结</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class='content'>
            
            <el-dialog :title="dialogtitle" :visible.sync="centerDialogVisible" width="60%" center>
                <el-form :model="form" :rules="rules" ref="form" label-width="140px" class="demo-ruleForm">
                    <el-form-item label="工作总结" prop="ws_job_content">
                        <el-input type="textarea" v-model="form.ws_job_content" :autosize="{ minRows: 8}" :disabled="editstatus?false:true"></el-input>
                    </el-form-item>
                    <el-form-item label="点评人" prop="commentatorname" v-if="!editstatus">
                        <el-input v-model="commentatorname" :autosize="{ minRows: 8}" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="点评时间" prop="ws_comment_time" v-if="!editstatus">
                        <el-input v-model="ws_comment_time" :autosize="{ minRows: 8}" disabled style="width:175px"></el-input>
                    </el-form-item>
                    <el-form-item label="点评内容" prop="ws_comment" v-if="!editstatus">
                        <el-input type="textarea" v-model="ws_comment" :autosize="{ minRows: 8}" disabled></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer" v-if="editstatus">
                    <el-button @click="cancel('form')" size="small">取 消</el-button>
                    <el-button type="primary" @click="submit('form')" size="small">确 定</el-button>
                </span>
            </el-dialog>
            <el-dialog title="经理点评" :visible.sync="dialogVisible" width="60%" center>
                <el-form :model="commentData" :rules="rules" ref="commentData" label-width="140px" class="demo-ruleForm">
                    <el-form-item label="点评：" prop="ws_comment">
                        <el-input type="textarea" v-model="commentData.ws_comment" :autosize="{ minRows: 8}"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="cancel('commentData')" size="small">取 消</el-button>
                    <el-button type="primary" @click="submitcomment('commentData')" size="small">确 定</el-button>
                </span>
            </el-dialog>
            <div class='list'>
                <el-table :data="list.data" tooltip-effect="light" style="width: 100%">

                    <el-table-column align="center" prop="ws_id" label="工作总结ID" width="120"></el-table-column>
                    <el-table-column align="center" prop="ws_title" label="标题" width="300"></el-table-column>
                    <el-table-column align="center" prop="departmentname" label="部门" width="120"></el-table-column>
                    <el-table-column align="center" prop="username" label="总结人" width="120"></el-table-column>
                    <el-table-column align="center" prop="ws_job_content" label="工作总结" width="160" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" prop="ws_create_time" label="总结时间" width="140"></el-table-column>
                    <el-table-column align="center" prop="ws_update_time" label="修改时间" width="140"></el-table-column>
                    <el-table-column align="center" prop="commentatorname" label="点评人" width="120"></el-table-column>
                    <el-table-column align="center" prop="ws_comment" label="点评" width="160" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" prop="ws_comment_time" label="点评时间" width="140"></el-table-column>
                    <el-table-column align="center" fixed="right" label="操作" width="160">
                    <template slot-scope="scope">
                        <el-button @click.native.prevent="look(scope.row)" type="text" size="small">查看详情</el-button>
                        <el-button @click.native.prevent="edit(scope.row)" type="text" size="small">编辑</el-button>
                        <el-button @click.native.prevent="comment(scope.row)" type="text" size="small">经理点评</el-button>
                        <el-button @click.native.prevent="del(scope.row)" type="text" size="small">删除</el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <el-pagination :current-page="current" @current-change="handleCurrentChange" :total="list.total" style="margin-top:30px;"></el-pagination>
            </div>
        </div>
    </div>
</template>
<style>
    .home .view-content{
        width: 87%;
    }
    .el-form-item__label,.el-form-item__content{
        font-size: 12px;
    }
    .el-input{
        padding-right: 5px;
    }
    .el-select-dropdown__item{
        font-size: 12px;
        padding: 0px 10px;
        height: 26px;
        line-height: 26px;
    }
    .el-input,.el-date-editor.el-input{
        width: 145px;
    }
</style>
<script>
    import conf from '../../config/userconf.js'
    import permconfig from "../../config/permconfig.js"
    export default {
        data() {
            return {
                list: [],  //
                info: {},
                searchData: {
                    peopleType: '1',
                    dateType: '1',
                    ws_did: '0',
                    ws_uid: '0',
                    start_time: '',
                    end_time: '',
                }, 
                current: 1,
                optionName: [],
                userType: [],
                dialogtitle: '添加工作总结',
                centerDialogVisible: false,
                dialogVisible: false,
                form: {
                    ws_title: '',
                    ws_job_content: '',
                },
                rules: {

                },
                zjstatus: 1,  //   1  添加   2  修改
                editstatus: true,   //是否可编辑
                commentData: {
                    ws_comment: '',
                },
                ws_id: '',  //工作总结id
                commentatorname: '',  //点评人
                ws_comment: '',  //点评内容
                ws_comment_time: '',  //点评时间
            }
        },
        methods: {
            /* 列表*/
            getList (data=Object()){
                data.page = this.current;
                conf.worksummary.list(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        console.log(res);
                        this.list = res.data.data;
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else if(res.data.code == -404){
                            this.list = [];
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            },
            /* 信息*/
            infos (data=Object()){
                conf.worksummary.info(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        this.info = res.data.data;
                        this.searchData.start_time = res.data.data.lastmonth;
                        this.searchData.end_time = res.data.data.month;
                        this.form.ws_title = res.data.data.title;
                        this.search();
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            },
            // 切换页码
            handleCurrentChange(val) {
                this.current = val;
                this.getList();
            },
            //查看详情
            look(row){
                var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_xiangqinggongzuozongjie)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
                this.editstatus = false;
                this.dialogtitle = this.form.ws_title;
                this.form.ws_job_content = row.ws_job_content;
                this.commentatorname = row.commentatorname;  //点评人
                this.ws_comment = row.ws_comment;  //点评内容
                this.ws_comment_time = row.ws_comment_time;  //点评时间
                this.centerDialogVisible = true;
            },
            //经理点评
            comment(row){
                var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_jinglidianping)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
                console.log(row);
                this.ws_id = row.ws_id;
                this.dialogVisible = true;
                 
            },
            //获取部门
            obtainName(data=Object()){
                conf.department.nameOpt(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        this.optionName = res.data.data;
                        // console.log(res); 
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else if(res.data.code == -404){
                            this.optionName = [];
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            },
            //获取部门员工
            obtainUser(val,data=Object()){
                this.userType = [];
                this.form.signatory = '';
                data.d_id = val;
                conf.department.userOpt(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        // console.log(res); 
                        this.userType = res.data.data;
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            },
            /*查询 */
            search () {
                let data  = this.searchData;
                this.getList(data)
            },
            /*取消 */
            cancel (formName) {
                this.centerDialogVisible = false;
                this.dialogVisible = false;
                this.$refs[formName].resetFields()
            },
            /*提交 */
            submit (formName) {
                console.log(formName);
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.judgeprimise();
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            //提交点评
            submitcomment (formName,data=Object()) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        data = this.commentData;
                        data.ws_id = this.ws_id;
                        conf.worksummary.comment(data,(state,res)=>{
                            if (state == 'success'&&res.data.code == 0){
                                this.search();
                                this.dialogVisible = false;
                                this.$message({
                                    type: 'success',
                                    message: '点评成功!'
                                });
                            }else if(state == 'success'&&res.data.code != 0){
                                if(res.data.code == 401){
                                    this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                                }else{
                                    this.$message({
                                        type: 'info',
                                        message: res.data.msg
                                    });
                                }
                            }
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            /*判断提交 */
            judgeprimise (data=Object()) {
                if (this.zjstatus == 1) {
                    conf.worksummary.add(this.form,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.search();
                            this.centerDialogVisible = false;
                            this.$message({
                                type: 'success',
                                message: '添加成功!'
                            });
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })
                }else if (this.zjstatus == 2){

                    data.ws_id = this.ws_id;
                    data.ws_job_content = this.form.ws_job_content;

                    conf.worksummary.edit(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.search();
                            this.centerDialogVisible = false;
                            this.$message({
                                type: 'success',
                                message: '修改成功!'
                            });
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })
                }
            },
            /*增 */
            add (formName) {
                this.zjstatus = 1;
                this.dialogtitle = this.form.ws_title;
                this.form.ws_job_content = '';
                this.editstatus = true;
                this.centerDialogVisible = true;
            },
            /*删 */
            del (row,data=Object()) {
                var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_shanchugongzuozongjie)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }


                console.log(row.ws_id);
                this.$confirm('确认删除 "'+row.username+'" 的工作总结吗?', '删除工作总结', {  
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    data.ws_id = row.ws_id;
                    conf.worksummary.del(data,(state,res)=>{
                        if (state == 'success'&&res.data.code == 0){
                            this.search();
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }else if(state == 'success'&&res.data.code != 0){
                            if(res.data.code == 401){
                                this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                            }else{
                                this.$message({
                                    type: 'info',
                                    message: res.data.msg
                                });
                            }
                        }
                    })

                }).catch(() => {
                    this.$message({
                    type: 'info',
                    message: '已取消删除'
                    });          
                });
            },
            /**改*/
            edit (val) {
                var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_bianjigongzuozongjie)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
                this.zjstatus = 2;
                this.editstatus = true;
                this.dialogtitle = val.ws_title;
                this.form = {
                    'ws_title': val.ws_title,
                    'ws_job_content': val.ws_job_content
                };
                this.ws_id = val.ws_id;
                this.centerDialogVisible = true;

            },
        },
        mounted (){
            this.$nextTick(function(){
                this.infos();
                this.obtainName();
            })
        },
    }
</script>